package com.dengyuanke.observerpattern.pullmodel;

import java.util.ArrayList;
import java.util.List;

/**
 * 抽象主题实现类
 * Created by dengyuanke on 2017/9/1.
 */
public class ConcreteSubject implements Subject {

    private List<Observer> observers=null;

    public ConcreteSubject(){
        observers=new ArrayList<Observer>();
    }

    @Override
    public void attach(Observer observer) {
        observers.add(observer);
    }

    @Override
    public void detach(Observer observer) {
        observers.remove(observer);
    }
    //抽象主题实现类的方法一
    public void oneMethod(){
        System.out.println("抽象主题实现类的方法一");
    }

    //抽象主题实现类的方法二
    public void twoMethod(){
        System.out.println("抽象主题实现类的方法二");
    }

    @Override
    public void notifyobserver() {
        for (Observer observer:observers) {
            observer.update(this);
        }
    }
}
